﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Skyhook.Core;

namespace Skyhook.Sprites
{
    internal class SpriteLayersLayout
    {
        const string LayersLayoutPrefix = "spritelayers.layerslayout";
        
        const string LayersOptionString = "layers";

        SortedDictionary<int, int> LayersLayout = null;

        public SpriteLayersLayout(string layerslayoutname)
        {
            string layers = null;//GameConfiguration.GetOptionValue<string>(GameConfiguration.MakeOptionName(LayersLayoutPrefix, layerslayoutname, LayersOptionString), "not_found");
            if (layers == "not_found")
            {
                throw new Exception("Layers for layout " + layerslayoutname + " not found.");
            }

            string[] layernames = layers.Split(',');
            LayersLayout = new SortedDictionary<int, int>();
            for (int i = 0; i < layernames.Length; i++)
            {
                LayersLayout.Add(i,SpriteLayers.ConvertLayerStringToInt(layernames[i]));
            }
        }

        public int this[int index]
        {
            get
            {
                if (index < 0 || index >= LayersLayout.Count)
                {
                    {
                        throw new Exception("Group index out of range");
                    }
                }
                return LayersLayout[index];
            }
        }
    }
}
